/*
 * Copyright (C) 2015 huwentao.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.mokey.core.demo;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by huwentao on 16/12/3.
 */

public class ItemAdapter extends RecyclerView.Adapter<ItemAdapter.ItemView> {
    private List<String> itemList = new ArrayList<>();
    private LayoutInflater inflater;

    public ItemAdapter(Context context, List<String> itemList) {
        if (itemList != null && itemList.size() > 0)
            this.itemList.addAll(itemList);
        inflater = LayoutInflater.from(context);
    }

    @Override
    public ItemView onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.layout_itemview,parent,false);
        return new ItemView(view);
    }

    @Override
    public void onBindViewHolder(ItemView holder, int position) {
        holder.itemText.setText(itemList.get(position));
    }

    @Override
    public int getItemCount() {
        return itemList.size();
    }

    class ItemView extends RecyclerView.ViewHolder {
        @BindView(R.id.itemText) TextView itemText;

        public ItemView(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
